package com.example.myapplication2;

import android.graphics.Color;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import androidx.viewpager.widget.PagerTabStrip;
import androidx.viewpager.widget.ViewPager;
import com.example.myapplication2.Adapter.FragmentAdapterDemo;
import java.util.ArrayList;
import java.util.HashMap;

public class FragmentDemo2Activity extends AppCompatActivity {
    public static final String[] array = {"Q", "A", "B","AAA","DDDDD"};
    public static final int[] ioc = {R.color.purple_200,R.color.black, R.color.teal_700, R.color.purple_200, R.color.teal_700};
    private ArrayList<HashMap<String, Object>> list;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fragment_demo2);
        list = new ArrayList<>();
        for (int i = 0; i < array.length; i++) {
            HashMap<String, Object> hashMap = new HashMap<>();
            hashMap.put("ioc", ioc[i]);
            hashMap.put("text", array[i]);
            list.add(hashMap);
        }
        //初始化翻页视图
        initViewPager();
        //初始化标签栏
        initPagerStrip();
    }

    private void initPagerStrip() {
        PagerTabStrip pagerTabStripTi = findViewById(R.id.PagerTabStripTi2);
        pagerTabStripTi.setTextColor(Color.BLACK);
    }

    private void initViewPager() {
        ViewPager viewPager = findViewById(R.id.PagerTabStrip2);
        //改用Fragment适配器
        FragmentAdapterDemo adapter = new FragmentAdapterDemo(getSupportFragmentManager(), list);
        viewPager.setAdapter(adapter);
    }
}